struct _StIconCache {
- int ref_count;
-
GMappedFile *map;
char *buffer;
guint32 last_chain_offset;
};
+static void
+clear_icon_cache (gpointer data)
+{
+ StIconCache *cache = data;
+ g_clear_pointer (&cache->map, g_mapped_file_unref);
+}
+
StIconCache *
st_icon_cache_ref (StIconCache *cache)
{
- cache->ref_count++;
- return cache;
+ return g_atomic_rc_box_acquire (cache);
}
void
st_icon_cache_unref (StIconCache *cache)
{
- cache->ref_count --;
-
- if (cache->ref_count == 0)
- {
- g_debug ("unmapping icon cache");
-
- if (cache->map)
- g_mapped_file_unref (cache->map);
- g_free (cache);
- }
+ g_atomic_rc_box_release_full (cache, clear_icon_cache);
}
StIconCache *
g_debug ("found icon cache for %s", path);
- cache = g_new0 (StIconCache, 1);
- cache->ref_count = 1;
+ cache = g_atomic_rc_box_new0 (StIconCache);
cache->map = map;
cache->buffer = g_mapped_file_get_contents (map);
{
StIconCache *cache;
- cache = g_new0 (StIconCache, 1);
- cache->ref_count = 1;
- cache->map = NULL;
+ cache = g_atomic_rc_box_new0 (StIconCache);
cache->buffer = (char *)data;
return cache;
StIconColors *
st_icon_colors_new (void)
{
- StIconColors *colors;
-
- colors = g_new0 (StIconColors, 1);
- colors->ref_count = 1;
-
- return colors;
+ return g_atomic_rc_box_new0 (StIconColors);
}
/**
st_icon_colors_ref (StIconColors *colors)
{
g_return_val_if_fail (colors != NULL, NULL);
- g_return_val_if_fail (colors->ref_count > 0, colors);
- g_atomic_int_inc ((volatile int *)&colors->ref_count);
- return colors;
+ return g_atomic_rc_box_acquire (colors);
}
/**
st_icon_colors_unref (StIconColors *colors)
{
g_return_if_fail (colors != NULL);
- g_return_if_fail (colors->ref_count > 0);
- if (g_atomic_int_dec_and_test ((volatile int *)&colors->ref_count))
- g_free (colors);
+ g_atomic_rc_box_release (colors);
}
/**
* icon.
*/
struct _StIconColors {
- volatile guint ref_count;
-
ClutterColor foreground;
ClutterColor warning;
ClutterColor error;
{
StShadow *shadow;
- shadow = g_new (StShadow, 1);
+ shadow = g_atomic_rc_box_new (StShadow);
shadow->color = *color;
shadow->xoffset = xoffset;
shadow->blur = blur;
shadow->spread = spread;
shadow->inset = inset;
- shadow->ref_count = 1;
return shadow;
}
st_shadow_ref (StShadow *shadow)
{
g_return_val_if_fail (shadow != NULL, NULL);
- g_return_val_if_fail (shadow->ref_count > 0, shadow);
- g_atomic_int_inc (&shadow->ref_count);
- return shadow;
+ return g_atomic_rc_box_acquire (shadow);
}
/**
st_shadow_unref (StShadow *shadow)
{
g_return_if_fail (shadow != NULL);
- g_return_if_fail (shadow->ref_count > 0);
- if (g_atomic_int_dec_and_test (&shadow->ref_count))
- g_free (shadow);
+ g_atomic_rc_box_release (shadow);
}
/**
gdouble blur;
gdouble spread;
gboolean inset;
- volatile int ref_count;
};
GType st_shadow_get_type (void) G_GNUC_CONST;